package com.yzh.wanandroid.base

import android.app.Application
import android.util.Log
import androidx.lifecycle.*
import com.yzh.wanandroid.repository.user.MainRepository
import com.yzh.wanandroid.utils.checkNetWork

open class BaseFragmentViewModel(application: Application) : AndroidViewModel(application),
    LifecycleObserver {

    private val TAG = "BaseFragmentViewModel"

    protected val mUserRepository: IBaseUserRepository by lazy { MainRepository() }

    /**
     * 判断是否有网络
     */
    fun netWorkCheck() = checkNetWork()

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    open fun onCreate(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onCreate")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    open fun onStart(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onStart")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    open fun onResume(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onResume")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    open fun onPause(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onPause")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    open fun onStop(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onStop")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    open fun onDestory(owner: LifecycleOwner) {
        Log.i(TAG, "Lifecycle onDestory")
    }
}